package com.uneed.widget;

import com.uneed.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

//Referenced classes of package com.dianping.widget:
//			DPBasicItem

public class HcTableView extends LinearLayout
{
	public static interface ClickListener
	{

		public abstract void onClick(int i);
	}


	private ClickListener mClickListener;
	private Context mContext;
	private int mIndexController;


	public HcTableView(Context context, AttributeSet attributeset)
	{
		super(context, attributeset);
		mIndexController = 0;
		mContext = context;
	}

	private int dip2px(float f)
	{
		return (int)(0.5F + f * mContext.getResources().getDisplayMetrics().density);
	}

	@Override
	public void addView(View view)
	{
		if (view instanceof HcBasicItem)
			((HcBasicItem)view).build();
		super.addView(view);
	}

/*	
	public void build()
	{
		if (getChildCount() <= 0) goto _L2; else goto _L1
_L1:
		int i;
		int j;
		setVisibility(0);
		mIndexController = 0;
		i = dip2px(10F);
		if (getChildCount() <= 1)
			break MISSING_BLOCK_LABEL_173;
		j = 0;
_L5:
		if (j < getChildCount()) goto _L4; else goto _L3
_L3:
		return;
_L2:
		setVisibility(8);
		  goto _L3
_L4:
		View view1 = getChildAt(j);
		if (mIndexController == 0)
			view1.setBackgroundResource(0x7f020010);
		else
		if (mIndexController == -1 + getChildCount())
			view1.setBackgroundResource(0x7f02000c);
		else
			view1.setBackgroundResource(0x7f02000e);
		if (view1 instanceof DPBasicItem)
			view1.setPadding(i, i, i, i);
		if (view1.isClickable())
		{
			view1.setTag(Integer.valueOf(mIndexController));
			view1.setOnClickListener(new android.view.View.OnClickListener() {

				final DPTableView this$0;

				public void onClick(View view2)
				{
					if (mClickListener != null)
						mClickListener.onClick(((Integer)view2.getTag()).intValue());
				}

			
			{
				this$0 = DPTableView.this;
				super();
			}
			}
);
		}
		mIndexController = 1 + mIndexController;
		j++;
		  goto _L5
		if (getChildCount() == 1)
		{
			View view = getChildAt(0);
			view.setBackgroundResource(0x7f02000f);
			if (view instanceof DPBasicItem)
				view.setPadding(i, i, i, i);
			if (view.isClickable())
			{
				view.setTag(Integer.valueOf(mIndexController));
				view.setOnClickListener(new android.view.View.OnClickListener() {

					final DPTableView this$0;

					public void onClick(View view2)
					{
						if (mClickListener != null)
							mClickListener.onClick(((Integer)view2.getTag()).intValue());
					}

			
			{
				this$0 = DPTableView.this;
				super();
			}
				}
);
			}
		}
		  goto _L3
	}

*/

	
	
	public void build()
	{
		
		if (getChildCount() <= 0) {
//			setVisibility(GONE);
			return;
		}
		int i;
		int j;
		setVisibility(VISIBLE);
		mIndexController = 0;
		i = dip2px(10F);
		
//		if (getChildCount() <= 1)  return;
//			break MISSING_BLOCK_LABEL_173;


		if (getChildCount() > 1) {
		j = 0;
		while (j < getChildCount()) {	
			View view1 = getChildAt(j);

			if (mIndexController == 0)
				view1.setBackgroundResource(R.drawable.background_view_rounded_top);
			else if (mIndexController == -1 + getChildCount())
				view1.setBackgroundResource(R.drawable.background_view_rounded_bottom);
			else
				view1.setBackgroundResource(R.drawable.background_view_rounded_middle);
			if (view1 instanceof HcBasicItem) view1.setPadding(i, i, i, i);
			if (view1.isClickable())
			{
				view1.setTag(Integer.valueOf(mIndexController));
				view1.setOnClickListener(new android.view.View.OnClickListener() {
					public void onClick(View view2)
					{
						if (mClickListener != null)
						mClickListener.onClick(((Integer)view2.getTag()).intValue());
					}
			
						{
//							this$0 = DPTableView.this;
			//				super();
						}
					}
					);
			}

			mIndexController = 1 + mIndexController;
			j++;
		}
		} else if (getChildCount() == 1) {
			View view = getChildAt(0);
			view.setBackgroundResource(R.drawable.background_view_rounded_single);
			if (view instanceof HcBasicItem)
				view.setPadding(i, i, i, i);
			if (view.isClickable())
			{
				view.setTag(Integer.valueOf(mIndexController));
				view.setOnClickListener(new android.view.View.OnClickListener() {

//					final DPTableView this$0;
					public void onClick(View view2)
					{
						if (mClickListener != null)
							mClickListener.onClick(((Integer)view2.getTag()).intValue());
					}

			
			{
//				this$0 = DPTableView.this;
		//		super();
			}
				}
				);
			}
		}
		
//		this.super();

//		  return;
	}


	@Override
	protected void onFinishInflate()
	{
		super.onFinishInflate();
		build();
	}

	public void removeClickListener()
	{
		mClickListener = null;
	}

	public void setClickListener(ClickListener clicklistener)
	{
		mClickListener = clicklistener;
	}

}
